<!--
 * @Author: xialang333@gmail.com
 * @Date: 2025-08-04 14:36:31
 * @LastEditTime: 2025-08-04 14:36:35
-->
{% extends "base.html" %}

{% block content %}
<div class="d-flex justify-content-between align-items-center mb-4">
    <h1>Exporters Dashboard</h1>
    <a href="/add-exporter" class="btn btn-primary">Add New Exporter</a>
</div>

{% if exporters %}
<div class="table-responsive">
    <table class="table table-striped table-hover">
        <thead class="table-dark">
            <tr>
                <th>Name</th>
                <th>Type</th>
                <th>Endpoint</th>
                <th>Status</th>
                <th>Scrape Interval</th>
                <th>Actions</th>
            </tr>
        </thead>
        <tbody>
            {% for exporter in exporters %}
            <tr>
                <td>{{ exporter.name }}</td>
                <td>{{ exporter.type }}</td>
                <td>{{ exporter.host }}:{{ exporter.port }}{{ exporter.path }}</td>
                <td>
                    <span class="badge bg-{{ 'success' if exporter.enabled else 'danger' }}">
                        {{ 'Enabled' if exporter.enabled else 'Disabled' }}
                    </span>
                </td>
                <td>{{ exporter.scrape_interval }}s</td>
                <td>
                    <a href="/edit-exporter/{{ exporter.id }}" class="btn btn-sm btn-outline-primary">Edit</a>
                    <button class="btn btn-sm btn-outline-danger" onclick="deleteExporter({{ exporter.id }})">Delete</button>
                </td>
            </tr>
            {% endfor %}
        </tbody>
    </table>
</div>
{% else %}
<div class="alert alert-info">No exporters configured yet. <a href="/add-exporter">Add your first exporter</a></div>
{% endif %}

<script>
async function deleteExporter(id) {
    if (confirm('Are you sure you want to delete this exporter?')) {
        const response = await fetch(`/api/exporters/${id}`, {
            method: 'DELETE'
        });
        if (response.ok) {
            window.location.reload();
        } else {
            alert('Failed to delete exporter');
        }
    }
}
</script>
{% endblock %}